#define _CRT_SECURE_NO_WARNINGS 1

  struct TreeNode {
 	int val;
 	struct TreeNode *left;
 	struct TreeNode *right;
 	TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
  };
 
#include <climits>
class Solution {
public:
    int prev = INT_MIN;
    bool isValidBST(TreeNode* root)
    {
        if (root == nullptr) return true;
        if (!isValidBST(root->left))
        {
            return false;
        }
        if (root->val < prev) return false;
        prev = root->val;
        if (!isValidBST(root->right))
        {
            return false;
        }
        return true;
    }
};